Freshers / Beginner level questions
Freshers / Beginner level questions & answers
Ques 1. What is SQL?
SQL (Structured Query Language) is a domain-specific language used for managing and manipulating relational databases.
Ques 2. What is the difference between SQL and MySQL?
SQL is a language, whereas MySQL is a relational database management system that uses SQL as its query language.
Ques 3. What is a primary key?
A primary key is a unique identifier for a record in a table. It must contain unique values and cannot be NULL.
Ques 4. What is an index in a database?
An index is a data structure that improves the speed of data retrieval operations on a database table at the cost of additional writes and storage space.
Ques 5. What is a foreign key?
A foreign key is a column or a set of columns in a table that refers to the primary key of another table, establishing a link between the two tables.
Ques 6. Write a SQL query to count the number of rows in a table.
SELECT COUNT(*) FROM table;
Ques 7. What is a view in a database?
A view is a virtual table based on the result of a SELECT query, and it does not store the data itself.
Example:
CREATE VIEW view_name AS SELECT column1, column2 FROM table WHERE condition;
Ques 8. Write a SQL query to update multiple rows in a table.
UPDATE table SET column1 = value1, column2 = value2 WHERE condition;
Ques 9. Explain the purpose of the ORDER BY clause.
The ORDER BY clause is used to sort the result set of a query in ascending or descending order based on one or more columns.
Example:
SELECT column1, column2 FROM table ORDER BY column1 DESC;
Ques 10. Write a SQL query to find the most recent record in a table.
SELECT * FROM table ORDER BY timestamp_column DESC LIMIT 1;
Ques 11. Explain the difference between CHAR and VARCHAR data types.
CHAR is a fixed-length string data type, while VARCHAR is a variable-length string data type. CHAR pads spaces to the maximum length, while VARCHAR only stores the actual data without padding.
Ques 12. What is the purpose of the SQL DISTINCT keyword?
The DISTINCT keyword is used to return unique values in the result set of a SELECT query by eliminating duplicate rows.
Example:
SELECT DISTINCT column FROM table;
Ques 13. What is the purpose of the SQL UPDATE statement?
The UPDATE statement is used to modify the existing records in a table by changing the values of one or more columns.
Example:
UPDATE table SET column1 = value1, column2 = value2 WHERE condition;
Ques 14. What is the purpose of the SQL LIKE operator?
The LIKE operator is used to search for a specified pattern in a column. It is often used with wildcard characters (% and _).
Example:
SELECT * FROM table WHERE column LIKE 'pattern%';
Ques 15. Write a SQL query to find the top N records from a table.
SELECT * FROM table ORDER BY column DESC LIMIT N;
Most helpful rated by users: